package cn.mesmile.thread.call;

import java.util.concurrent.*;

/**
 * @author zb
 * @date 2020/12/28 9:54
 * @Description
 */
public class TreadPoolDemo {

    public static void main(String[] args) {
        // 创建线程池
        ExecutorService executorService =
                Executors.newCachedThreadPool();
        // 向线程池中提交任务
        Future<String> future = executorService.submit(new MyCallable());
        Future<String> future2 = executorService.submit(new MyCallable());
        // 判断任务是否完成
        if (!future.isDone()) {
            System.out.println("task not finished, please wait~~");
        }
        try {
            System.out.println("future.get() = " + future.get());
            System.out.println("future2.get() = " + future2.get());

        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        } finally {
            // 将线程池关闭
            executorService.shutdown();
        }
    }
}
